package com.bugpool.leilema.freamwork.datascope.impl;

import cn.hutool.core.util.StrUtil;
import com.bugpool.leilema.freamwork.datascope.DataScopeStrategy;
import com.bugpool.leilema.tc.bean.dto.DataScopeDTO;

/**
 * @Author wh
 * @Description 基类 提供默认方法
 * @Date 2023/6/13 18:04
 * @Version 1.0
 **/
public abstract class AbstractDataScope implements DataScopeStrategy {


    protected static final String SUFFIX = ".";

    protected static final String CHARACTER = " ";




    @Override
    public StringBuilder enhancedSql(DataScopeDTO dataScopeDTO) {
        String prefix = getPrefix(dataScopeDTO.getTbAlias());
        dataScopeDTO.setTbAlias(prefix);
        return this.sqlEnhance(dataScopeDTO);
    }


    protected abstract StringBuilder sqlEnhance(DataScopeDTO dataScopeDTO);


    /**
     * 主表别名获取
     * @param tbAlias
     * @return
     */
    protected String getPrefix(String tbAlias) {
        if (StrUtil.isEmpty(tbAlias)) {
            return CHARACTER;
        }
        StringBuilder sb = new StringBuilder();
        return sb.append(tbAlias).toString();
    }


}
